#ifndef RTDB_H
#define RTDB_H

#include <QObject>
#include <QSharedMemory>
#include "comstruct.h"

class CRTDB : public QObject
{
	Q_OBJECT

public:
	CRTDB(int iBattStackNum/*电池堆-转发模块数*/, int iBANum/*BA数,100个通用输入寄存器*/, int iBattBankNum/*电池组数*/, QObject *parent = 0);
	~CRTDB();

public:
	int initRTDB(bool bReadWrite = false);

	CBattStack* getStack(int iBattStackIndex);
	CBattBank* getBank(int iBattBankIndex);
	CBAComReg* getBAComReg(int iBAIndex);

	int getComInputRegValBA(int iBAIndex, quint16 usRegAddr, quint16& usVal);
	int getComHoldRegValBA(int iBAIndex, quint16 usRegAddr, quint16& usVal);

	// Alarm
	CBankAlarm* getBankAlarm(int iBattBankIndex);
	SAlarm* getFirstAlarm(int iBattBankIndex);
	SAlarmParam* getAlarmParam(int iBattBankIndex);

	SAlarm* getFirstAlarm(CBankAlarm* pBankAlarm);
	SAlarm* getAlarm(CBankAlarm* pBankAlarm, quint16 usNo);

	// DryWet
	void setDryWetCtrl(CBattBank* pBattBank, quint16 usDry1Ctrl, quint16 usDry2Ctrl, quint16 usDry3Ctrl, quint16 usDry4Ctrl, quint16 usWetCtrl, int iDry1CtrlNum, int iDry2CtrlNum, int iDry3CtrlNum, int iDry4CtrlNum, int iWetCtrlNum);
	void setDryCtrl1(CBattBank* pBattBank, quint16 usDry1Ctrl, quint16 usDry2Ctrl, int iDry1CtrlNum, int iDry2CtrlNum);
	void setDryCtrl2(CBattBank* pBattBank, quint16 usDry3Ctrl, quint16 usDry4Ctrl, int iDry3CtrlNum, int iDry4CtrlNum);
	void setWetCtrl(CBattBank* pBattBank, quint16 usWetCtrl, int iWetCtrlNum);

signals:
	void addLog(int iLogType, const QString& strLog);

private:
	int m_iBattStackNum;  /*电池堆-转发模块数*/
	int m_iBattBankNum;   /*电池组数*/
	int m_iBANum;         /*BA 数*/
	
	QSharedMemory* m_pSharedMemery;
	char* m_pRTDBData;
};

#endif // RTDB_H
